//--------------------------------------------------------------------------------
// This file is a portion of the D2D1Renderer.  It is distributed
// under the MIT License, available in the root of this distribution and 
// at the following URL:
//
// http://www.opensource.org/licenses/mit-license.php
//
// Copyright (c) Mirco Timmermann
//
// Sources: http://www.w3.org/TR/2dcontext/ , http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html
//--------------------------------------------------------------------------------
#pragma once

#ifndef __CANVAS_FLOAT
#define __CANVAS_FLOAT
#endif

#include <string>
#include "..\CanvasGradient.h"

class CanvasRenderingContext2D {

///////////////////////////////////////////////////////////////////////////////////////////////
//                                     DRAW INTERFACE                                        //
///////////////////////////////////////////////////////////////////////////////////////////////

public:
	
	CanvasRenderingContext2D::CanvasRenderingContext2D() {
		globalAlpha = 1.0; // (default 1.0)
        globalCompositeOperation = ""; // (default source-over)

		strokeStyle = "#000000"; // (default black)
        fillStyle = "#000000"; // (default black)

		shadowOffsetX = 0.0; // (default 0)
        shadowOffsetY = 0.0; // (default 0)
        shadowBlur = 0.0; // (default 0)
        shadowColor = "#000000"; // (default transparent black)
	}

	// state
	virtual void save() = 0; // push state on state stack
	virtual void restore() = 0; // pop state stack and restore state

	// compositing
#ifdef __CANVAS_DOUBLE
        double globalAlpha; // (default 1.0)
#endif
#ifdef __CANVAS_FLOAT
		float globalAlpha; // (default 1.0)
#endif

        std::string globalCompositeOperation; // (default source-over)

	// colors and styles (see also the CanvasLineStyles interface)
        std::string strokeStyle; // (default black)
        std::string fillStyle; // (default black)


		//http://stackoverflow.com/questions/7031330/rectangular-gradient-with-html5-canvas-element
#ifdef __CANVAS_DOUBLE
        virtual CanvasGradient createLinearGradient(double x0, double y0, double x1, double y1) = 0;
		virtual CanvasGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) = 0;
		//virtual CanvasPattern createPattern((HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image, DOMString repetition) = 0;
#endif
#ifdef __CANVAS_FLOAT
		virtual CanvasGradient createLinearGradient(float x0, float y0, float x1, float y1) = 0;
		virtual CanvasGradient createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1) = 0;
		//CanvasPattern createPattern((HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image, DOMString repetition) = 0;
#endif
		

		//CanvasGradient createLinearGradient(double x0, double y0, double x1, double y1);
		//CanvasGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1);
		//CanvasPattern createPattern((HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image, DOMString repetition);

	// shadows
#ifdef __CANVAS_DOUBLE
         double shadowOffsetX; // (default 0)
         double shadowOffsetY; // (default 0)
         double shadowBlur; // (default 0)
#endif
#ifdef __CANVAS_FLOAT
		 float shadowOffsetX; // (default 0)
         float shadowOffsetY; // (default 0)
         float shadowBlur; // (default 0)
#endif

         std::string shadowColor; // (default transparent black)

	// rects
#ifdef __CANVAS_DOUBLE
	virtual void clearRect(double x, double y, double w, double h) = 0;
	virtual void fillRect(double x, double y, double w, double h) = 0;
	virtual void strokeRect(double x, double y, double w, double h) = 0;
#endif
#ifdef __CANVAS_FLOAT
	virtual void clearRect(float x, float y, float w, float h) = 0;
	virtual void fillRect(float x, float y, float w, float h) = 0;
	virtual void strokeRect(float x, float y, float w, float h) = 0;
#endif

	// current default path API (see also CanvasPathMethods)
	virtual void beginPath() = 0;
	virtual void fill() = 0;
	virtual void stroke() = 0;
	//void drawSystemFocusRing(Element element);
	//bool drawCustomFocusRing(Element element);
	//void scrollPathIntoView();
	virtual void clip() = 0;
	//bool isPointInPath(double x, double y);

	// text (see also the CanvasText interface)
#ifdef __CANVAS_DOUBLE
	virtual void fillText(std::string text, double x, double y, double maxWidth = 0) = 0;
	virtual void strokeText(std::string text, double x, double y, double maxWidth = 0) = 0;
#endif
#ifdef __CANVAS_FLOAT
	virtual void fillText(std::string text, float x, float y, float maxWidth = 0) = 0;
	virtual void strokeText(std::string text, float x, float y, float maxWidth = 0) = 0;
#endif
	//TextMetrics measureText(std::string text);

	// drawing images
	//void drawImage(Image image, double dx, double dy);
	//void drawImage(Image image, double dx, double dy, double dw, double dh);
	//void drawImage(Image image, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh);

	// pixel manipulation
	//ImageData createImageData(double sw, double sh);
	//ImageData createImageData(ImageData imagedata);
	//ImageData getImageData(double sx, double sy, double sw, double sh);
	//void putImageData(ImageData imagedata, double dx, double dy);
	//void putImageData(ImageData imagedata, double dx, double dy, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight);

};

/*
	ID2D1StrokeStyle* _strokeStyle;
	ID2D1LinearGradientBrush* _pLinearGradientBrush;
	ID2D1PathGeometry* _pathGeometry;

	IDWriteFactory* dWriteFactory;
	IDWriteTextFormat* _textFormat;
	IDWriteTextLayout* _textLayout;
*/